import defaultSettings from '@neu/biz-core/settings'
import { getTheme, setTheme } from '@neu/biz-core/utils/utils'

const { title, showSettings, tagsView, fixedHeader, sidebarLogo, searchSettings, fontSettings, themeList } = defaultSettings

const state = {
  title: title,
  themeList: themeList,
  activeTheme: getTheme(),
  showSettings: showSettings,
  tagsView: tagsView,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  searchSettings: searchSettings,
  fontSettings: fontSettings
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  },
  SET_ACTIVE_THEME: (state, theme) => {
    state.activeTheme = theme
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  },
  setActiveTheme({ commit }, theme) {
    setTheme(theme)
    commit('SET_ACTIVE_THEME', theme)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

